package docker

import (
	"context"
	"github.com/jinzhu/copier"

	"docker/internal/svc"
	"docker/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DockerRunCmdsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDockerRunCmdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DockerRunCmdsLogic {
	return &DockerRunCmdsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DockerRunCmdsLogic) DockerRunCmds() (resp *types.DockerRunResp, err error) {

	model := l.svcCtx.DockerRunModel
	all, err := model.FindAll(l.ctx)
	if err != nil {

	}
	var datas []types.DockerRunData

	for _, run := range all {
		id := run.ID.Hex()
		data := types.DockerRunData{}
		copier.Copy(&data, &run)
		data.Id = id
		datas = append(datas, data)
	}
	return &types.DockerRunResp{
		Result: types.Result{
			Code:      200,
			Message:   "",
			ExtInfo:   "",
			Timestamp: 0,
		},
		Data: datas,
	}, err
}
